#include "WString.h"
#include "BoardAssembly.h"
#include "mock/EthernetMock.h"
#include "mock/ServiceMock.h"

class BoardAssemblyTest : public ::testing::Test {
public:
	BoardAssemblyTest() : s(a, m.getRouter(), l), m(a, e, l, ""){}
protected:
	EthernetMock e;
	ArduinoMock a;
	LoggerMock l;
	BoardAssembly m;
	ServiceMock s;
	
virtual void SetUp() {
	m.getRouter().addService(s);
}
};

TEST_F(BoardAssemblyTest, tickShallBePropagated){
	EXPECT_CALL(a, milliseconds())
		.Times(1).WillOnce(Return(10));
	EXPECT_CALL(s, tick(10))
		.Times(1);

	EXPECT_CALL(e, isMessageReady()).
		Times(1).
		WillOnce(Return(false));
	EXPECT_CALL(e, isInitialized()).
		Times(1).
		WillOnce(Return(true));

	m.loop();
}

TEST_F(BoardAssemblyTest, incomingEthernetMessage){
	EXPECT_CALL(a, milliseconds())
		.Times(1).WillOnce(Return(10));

	EXPECT_CALL(s, tick(10))
		.Times(1);

	EXPECT_CALL(e, isMessageReady()).
		Times(1).
		WillOnce(Return(true));
	EXPECT_CALL(e, isInitialized()).
		Times(1).
		WillOnce(Return(true));

	EXPECT_CALL(e, getMessage()).
		Times(1).
		WillOnce(Return("Ala ma kota"));

	EXPECT_CALL(s, onMessage(String("Ala ma kota"))).
		Times(1);
	
	m.loop();
}

TEST_F(BoardAssemblyTest, serviceMessage){
	EXPECT_CALL(e, sendMessage(String("Ala ma kota"))).
		Times(1);
	s.postMessage("Ala ma kota");
}
